package com.hotel.controller;

import com.hotel.common.AjaxResult;
import com.hotel.domain.service.VipInfoService;
import com.hotel.pojo.VipInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/vipInfo")
public class VipInfoController {

    @Autowired
    private VipInfoService vipInfoService;

    /**
     * 获取Vip信息列表
     * @param vipInfo vip信息对象
     * @param page 页码
     * @param perPage 每页的条数
     * @return AjaxResult
     */
    @GetMapping("/{page}/{perPage}")
    @ResponseBody
    public AjaxResult getVipInfoList(VipInfo vipInfo, @PathVariable("page") int page, @PathVariable("perPage") int perPage){
        return AjaxResult.queryAjax(vipInfoService.getVipInfoList(vipInfo, page, perPage));
    }

    /**
     * 新增Vip客户
     * @param vipInfo Vip信息对象
     * @return AjaxResult
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addVipInfo(@RequestBody VipInfo vipInfo){
        return AjaxResult.updateAjax(vipInfoService.addVipInfo(vipInfo));
    }

    /**
     * 更新Vip信息
     * @param vipInfo Vip信息对象
     * @return AjaxResult
     */
    @PostMapping("/update")
    @ResponseBody
    public AjaxResult updateVipInfo(@RequestBody VipInfo vipInfo){
        return AjaxResult.updateAjax(vipInfoService.updateVipInfo(vipInfo));
    }

    /**
     * 逻辑删除vip
     * @param vipId Vip_id
     * @return AjaxResult
     */
    @PostMapping("/delete")
    @ResponseBody
    public AjaxResult deleteVipInfo(@RequestBody int vipId){
        VipInfo vipInfo = new VipInfo();
        vipInfo.setVipId(vipId);
        vipInfo.setVipDel(1);
        return AjaxResult.updateAjax(vipInfoService.updateVipInfo(vipInfo));
    }

}
